package com.books.mapper.book;/*
 *@Auther Zhourui
 *@data 2021/9/29  20:02
 *@Email 1605576647@qq.com
 */

import com.books.model.entity.book.Books;
import com.books.model.entity.book.Ebook;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface EbookMapper {
    @Select("select * from  e_book where ebk_id=#{id}")
    Ebook getById(Integer id);

    @Select("select * from e_book")
    List<Ebook> findAll();

    //多条件参数
    List<Ebook> getAll(@Param("title") String title, @Param("categoryId") Integer categoryId);

    /**
     * 根据标题模糊查询书籍
     * @param title
     * @return
     */
    @Select("select * from e_book where title like '%${title}%'")
    List<Ebook> findByBookName(String title);

    /**
     * 根据作者模糊查询
     * @param author
     * @return
     */
    @Select("select * from e_book where author like '%${author}%'")
    List<Ebook> findByAuthor(String author);

    /**
     * 根据类别查询
     * @param categoryId
     * @return
     */
    @Select("select * from e_book where category_id=#{categoryId}")
    List<Ebook> findByBookType(Integer categoryId);

    @Delete("delete from e_book where ebk_id=#{ebkId}")
    void delByBkId(Integer ebkId);

    @Update("update e_book set price=#{price} where ebk_id=#{ebkId}")
    void updateBook(Integer ebkId,Double price);

    @Insert("insert into e_book values(null,#{title},#{price},#{author},#{date},#{pictureUrl},#{categoryId})")
    void addBook(Ebook ebook);
}
